< previous page page_425 next page >

Page 425
Tutorial 11
Reading the Event Log
7017a6ead0e3c4111b47a554df321e9f.gif 7017a6ead0e3c4111b47a554df321e9f.gif
The following article was originally published in my column in Pinnacle's Visual Basic Developer Newsletter. It is such a perfect case study for this book that I decided to reprint it here, even though some of you may have read it in the original form. This tutorial requires Windows NT.
You may have noticed that many of my columns are inspired by questions that arrive relating to either Desaware's products or my books. One of the reasons for this is that any time I need inspiration for a column, I turn to my e-mail in-box for inspiration. Many of these questions never get answered because, although I would like to provide technical support for my Win32 API book (Dan Appleman's Visual Basic Programmer's Guide to the Win32 API), it's simply not economically feasible to do so. I try to offer quick answers to those questions I can answer easily, but those that take substantial effort often get short shriftunless, of course, I base an article on them.
Today's inspiration came from the following question:
7017a6ead0e3c4111b47a554df321e9f.gif 7017a6ead0e3c4111b47a554df321e9f.gif
I am trying to call the ReadEventLog function with VB. I have tons of examples with VC++ but nothing for VB. The part that's killing me is the C type casting of a pointer. This is the code I am trying to convert. Any help would be greatly appreciated.
7017a6ead0e3c4111b47a554df321e9f.gif
EVENTLOGRECORD *pevlr;
BYTE bBuffer[BUFFER_SIZE];
DWORD dwRead, dwNeeded, cRecords, dwThisRecord = 0;

h = OpenEventLog(NULL,"Application");
if (h == NULL) ErrorExit("could not open Application event log");

pevlr = (EVENTLOGRECORD *) &bBuffer;

while (ReadEventLog(h, EVENTLOG_FORWARDS_READ |
EVENTLOG_SEQUENTIAL_READ, 0, pevlr, BUFFER_SIZE, &dwRead, &dwNeeded))
   while (dwRead > 0) {
      printf("%02d Event ID: 0x%08X ", dwThisRecord++, pevlr->EventID);
      printf("EventType: %d Source: %s\n", pevlr->EventType, (LPSTR)((LPBYTE)

 
< previous page page_425 next page >